package com.example.myui.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.myui.R;
import com.example.myui.model.SchoolModel;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyProActivity extends AppCompatActivity {
    @BindView(R.id.recyclerview1)
    RecyclerView recyclerView1;
    @BindView(R.id.recyclerview2)
    RecyclerView recyclerView2;
    @BindView(R.id.recyclerview3)
    RecyclerView recyclerView3;
    private ArrayList<SchoolModel> models1;
    private ArrayList<SchoolModel> models2;
    private ArrayList<SchoolModel> models3;
    private String TAG = MyProActivity.class.getSimpleName();
    private MyAdapter myAdapter1;
    private MyAdapter myAdapter2;
    private MyAdapter myAdapter3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_pro);
        ButterKnife.bind(this);


        initData();
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(MyProActivity.this, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        LinearLayoutManager layoutManager2 = new LinearLayoutManager(MyProActivity.this, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        LinearLayoutManager layoutManager3 = new LinearLayoutManager(MyProActivity.this, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        recyclerView1.setLayoutManager(layoutManager1);
        recyclerView2.setLayoutManager(layoutManager2);
        recyclerView3.setLayoutManager(layoutManager3);

        myAdapter1 = new MyAdapter(MyProActivity.this, models1);
        myAdapter2 = new MyAdapter(MyProActivity.this, models2);
        myAdapter3 = new MyAdapter(MyProActivity.this, models3);
        recyclerView1.setAdapter(myAdapter1);
        recyclerView2.setAdapter(myAdapter2);
        recyclerView3.setAdapter(myAdapter3);

    }

    @OnClick(R.id.tv_edu)
    public void doEdu(View view) {
        Log.i(TAG, "doEdu: ");
        startActivityForResult(new Intent(MyProActivity.this, EditActivity.class), 1001);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1001) {
            if (resultCode == 101) {
                Log.i(TAG, "onActivityResult: " + resultCode);
                models1.add(new SchoolModel("重庆邮电大学11", "2010-2014"));
                myAdapter1.notifyDataSetChanged();
            } else if (resultCode == 102) {
                Log.i(TAG, "onActivityResult: " + resultCode);
            }
        }
    }

    private void initData() {
        models1 = new ArrayList<>();
        models1.add(new SchoolModel("重庆邮电大学", "2010-2014"));
        models1.add(new SchoolModel("重庆邮电大学", "2010-2014"));

        models2 = new ArrayList<>();
        models2.add(new SchoolModel("广东公司", "2014-2015"));
        models2.add(new SchoolModel("广东公司", "2014-2015"));

        models3 = new ArrayList<>();
        models3.add(new SchoolModel("某公司", "2016-2017"));
        models3.add(new SchoolModel("某公司", "2016-2017"));
    }
}
